<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head th:include="common">
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<button class="btn btn-success" onclick="openAddDialog()"> 详情</button>
<div class="modal fade" id="addDialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="myModalLabel">详情</h4>
            </div>
            <div class="modal-body">
                <form id="addForm" action="<%=path%>/erp/addComm.do" method="post">
                    <div class="form-group">
                        <label for="cname">商品id</label>
                        <input type="text" name="goodsId" class="form-control" id="cname" readonly>
                    </div>
                    <div class="form-group">
                        <label for="cname">商品名称</label>
                        <input type="text" name="goodsName" class="form-control" id="cname" placeholder="商品名称">
                    </div>
                    <div class="form-group">
                        <label for="csourcePrice">地址</label>
                        <input type="text" name="goodsAdress" class="form-control" id="csourcePrice" placeholder="进价">
                    </div>
                    <div class="form-group city">
                        <label for="ctype">城市</label>
                        <select name="cityName" id="addidCity">
                        </select>
                    </div>
                    <div class="form-group type">
                        <label for="ctype">类型</label>
                        <select name="goodsTypeId" id="addidType">
                        </select>
                    </div>
                    <div class="form-group active">
                        <label for="ctype">系列活动</label>
                        <select name="goodsActivityNumber" id="addidActive">
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="ccount">主要演员</label>
                        <input type="text" name="goodsMainActor" class="form-control" id="ccount" placeholder="商品数量">
                    </div>
                    <div class="form-group">
                        <label for="ccount">推荐度</label>
                        <input type="text" name="goodsRecommendedDegree" class="form-control" id="ccount" placeholder="商品数量">
                    </div>
                    <div class="form-group radi">
                        <input type="radio" name="goodsUndeterminedActive" value="1">待定
                        <input type="radio" name="goodsUndeterminedActive" value="2">非待定
                    </div>
                    <div class="form-group">
                        <img src="" id="myimg" style="width: 100px;height: 100px">
                        <button type="button" class="btn btn-success" onclick="openImg()">图片</button>
                        <label for="cimg">图片</label>
                        <div class="modal fade" id="imgDialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                            <div class="modal-dialog" role="document" >
                                <div class="modal-content" style="width:400px">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                                        <h4 class="modal-title" id="myModalLabel">上传</h4>
                                    </div>
                                    <div class="modal-body">
                                        <input id="filePortrait" type="file" name="imgfile"/>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭</button>
                                        <button type="button" id="btn_submit" class="btn btn-primary" alert="submitFrorm()"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>保存</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <input type="text" name="goodsImg" class="form-control" id="cimg" placeholder="图片">
                    </div>
                    <!--场次回显-->
                    <div id="ronda"></div>
                </form>
            </div>
            <div class="modal-footer">
                <!--<button type="button" class="btn btn-default" id="btn_submit" onclick="updateGoods()">保存</button>-->
                <button type="button" class="btn btn-default" id="back_submit" onclick="backGoods()">返回</button>
                <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭</button>
            </div>
        </div>
    </div>
</div>
</body>
<script th:inline="javascript">
    //打开新增
    $("#addDialog").modal();
    function openAddDialog(){
        //$('#loginDialog').modal();
    }
    var boo1=false;
    //王乐城市动态下拉
    $.ajax({
        url:"/goodsConsummer/getCitySelect",
        async:false,
        success:function(data){
            var str="";
            str+="<option value='0'>请选择</option>";
            for (var i = 0; i < data.length; i++) {
                str+="<option value='"+data[i].cityId+"'>"+data[i].cityName+"</option>"
            }
            $("#addidCity").append(str);
            $("#addidCity").selectpicker("refresh");
            boo1=true;
        }
    })
    var boo2 = false;
    //类型动态下拉
    $.ajax({
        url:"/goodsConsummer/getTypeSelect",
        async:false,
        success:function(data){
            var str="";
            str+="<option value='0'>请选择</option>";
            for (var i = 0; i < data.length; i++) {
                str+="<option value='"+data[i].goodsTypeId+"'>"+data[i].goodsTypeName+"</option>"
            }
            $("#addidType").append(str);
            $("#addidType").selectpicker("refresh");
            boo2=true;
        }
    })
    var boo3=false;
    //系列活动动态下拉
    $.ajax({
        url:"/goodsConsummer/getActiveSelect",
        async:false,
        success:function(data){
            var str="";
            str+="<option value='0'>请选择</option>";
            for (var i = 0; i < data.length; i++) {
                str+="<option value='"+data[i].activityId+"'>"+data[i].activityName+"</option>"
            }
            $("#addidActive").append(str);
            $("#addidActive").selectpicker("refresh");
            boo3=true;
        }
    })
    var interval = setTimeout("show()",500);
    function show(){
        console.log( boo3);
        /*回显商品*/
        if(true){
            var id = [[${id}]];
         //   alert(22)
            $.ajax({
                url:"/goodsConsummer/getGoodsById",
                data:{goodsId:id},
                success:function(data){
                    for(var i in data){
                        $("#addForm input").each(function(index,dom){
                            if (i==$(dom).attr("name")) {
                                $(dom).val(data[i])
                            }
                        })
                    }
                    $("#myimg").prop("src",data.goodsImg);
                    $(".radi input[value='"+data.goodsUndeterminedActive+"']").prop("checked",true);
                    $(".city option[value='"+data.goodsCityId+"']").prop("selected",true);
                    $(".type option[value='"+data.goodsTypeId+"']").prop("selected",true);
                    $(".active option[value='"+data.goodsActivityNumber+"']").prop("selected",true);
                    clearInterval(interval);
                    console.log(data);
                    //场次回显
                    var str = "";
                    for(var i=0;i<data.goodsSessionEntityList.length;i++){
                        str+="-----------------------------------------------场次"+(i+1)+"--------------------------------------------------<br>"
                            +"场次id<input name='goodsSessionEntityList["+i+"].sessionId' value='"+data.goodsSessionEntityList[i].sessionId+"' readonly><br>"
                            +"结束时间<input name='goodsSessionEntityList["+i+"].sessionTime' value='"+data.goodsSessionEntityList[i].sessionTime+"'><br>"
                            +"开始时间<input name='goodsSessionEntityList["+i+"].endTime' value='"+data.goodsSessionEntityList[i].endTime+"'><br>"
                            +"线上场次描述<input name='goodsSessionEntityList["+i+"].onlineDescription' value='"+data.goodsSessionEntityList[i].onlineDescription+"'><br>"
                        for(var j=0;j<data.goodsSessionEntityList[i].goodsLeaveList.length;j++){
                            str+="+++++++++++++++++++++++++++++++档次"+(i+1)+"-"+(j+1)+"++++++++++++++++++++++++++++++++<br>"
                                +"\t档次id<input name='goodsSessionEntityList["+i+"].goodsLeaveList["+j+"].leaveId' value='"+data.goodsSessionEntityList[i].goodsLeaveList[j].leaveId+"' readonly><br>"
                                +"\t档次名<input name='goodsSessionEntityList["+i+"].goodsLeaveList["+j+"].leaveName' value='"+data.goodsSessionEntityList[i].goodsLeaveList[j].leaveName+"'><br>"
                                +"\t该档次的商品售价<input name='goodsSessionEntityList["+i+"].goodsLeaveList["+j+"].goodsPrice' value='"+data.goodsSessionEntityList[i].goodsLeaveList[j].goodsPrice+"'><br>"
                                +"\t总票数<input name='goodsSessionEntityList["+i+"].goodsLeaveList["+j+"].goodsCount' value='"+data.goodsSessionEntityList[i].goodsLeaveList[j].goodsCount+"'><br>"
                                +"\t出售量<input name='goodsSessionEntityList["+i+"].goodsLeaveList["+j+"].soldCount' value='"+data.goodsSessionEntityList[i].goodsLeaveList[j].soldCount+"'><br>"
                                +"\t档次描述<input name='goodsSessionEntityList["+i+"].goodsLeaveList["+j+"].leaveInfo' value='"+data.goodsSessionEntityList[i].goodsLeaveList[j].leaveInfo+"'><br>"
                                +"\t成本价格<input name='goodsSessionEntityList["+i+"].goodsLeaveList["+j+"].truePrice' value='"+data.goodsSessionEntityList[i].goodsLeaveList[j].truePrice+"'><br>"

                        }
                    }
                //    alert(str)
                    $("#ronda").append(str);
                }
            })
        }
    }
    //返回
    function backGoods(){
        location.href="/jumpPage/jumpPage?page=goods"
    }
</script>
</html>